package sismed.gui.comando;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sismed.exception.DAOException;
import sismed.negocio.fachada.Fachada;
import sismed.negocio.modelo.Exame;

public class ComandoDetalharExame extends ComandoGenerico {

	@Override
	public void executar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if( request.getSession().getAttribute("tipoUsuario").equals( null ) )				
			response.sendRedirect("login.jsp");
		else{
			System.out.println("Detalhar Exame");
			Fachada fachada = Fachada.getInstance();
			String idExame = request.getParameter("id");
			Exame exame = null;
			try {
				exame = fachada.recuperarExame(idExame);
			} catch (DAOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {		
				request.setAttribute("Exame", exame);
				request.getRequestDispatcher("PacienteVisualizarExames.jsp").forward(request, response);	
			} 
			catch (Exception e) {
				response.sendRedirect("erro.jsp?msgerro=Erro ao recuperar mensagens.");	
			}
		}
	}
}
